//
//  TradeListTopVM.swift
//  kxf
//
//  Created by Mac on 2024/3/20.
//

import Foundation
import UIKit

class TradeListTopVM: UIView {
    
    let selfHeight = kFitWidth(200)
    
    override init(frame:CGRect){
        super.init(frame: CGRect.init(x: 0, y: frame.origin.y, width: SCREEN_WIDHT, height: selfHeight))
        self.backgroundColor = .white//WHColorWithAlpha(colorStr: "FFB2B2", alpha: 0.12)
        self.isUserInteractionEnabled = true
        self.layer.cornerRadius = kFitWidth(8)
        self.clipsToBounds = true
        
        initUI()
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    lazy var titleVm : RegisterViewHeadTitleVM = {
        let vm = RegisterViewHeadTitleVM.init(frame: .zero)
        vm.titleLabel.text = "交易记录"
//        vm.backgroundColor = .clear
        return vm
    }()
    lazy var bgImgView : UIImageView = {
        let img = UIImageView()
        img.setImgLocal(imgName: "rebate_img_bg")
        
        return img
    }()
    lazy var settleMoneyLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .THEME
        lab.font = .systemFont(ofSize: 24, weight: .medium)
        return lab
    }()
    lazy var settleMoneyLab : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 14, weight: .medium)
        lab.text = "累计交易金额（元）"
        
        return lab
    }()
    lazy var handFeeLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 20, weight: .medium)
        
        return lab
    }()
    lazy var handFeeLab : UILabel = {
        let lab = UILabel()
        lab.textColor = .COLOR_TEXT_BLACK666
        lab.font = .systemFont(ofSize: 12, weight: .regular)
        lab.text = "累计交易笔数"
        
        return lab
    }()
}

extension TradeListTopVM{
    func updateUI(dict:NSDictionary) {
        settleMoneyLabel.text = WHUtils.convertStringToString("\(dict["userTotalAmount"]as? Double ?? 0.0)")
        handFeeLabel.text = "\(dict["userTradeCount"]as? Int ?? 0)"
        
        //tradeCount  totalAmount   userTotalAmount   userTradeCount
    }
}

extension TradeListTopVM{
    func initUI(){
        addSubview(titleVm)
        
        addSubview(bgImgView)
        addSubview(settleMoneyLabel)
        addSubview(settleMoneyLab)
        addSubview(handFeeLabel)
        addSubview(handFeeLab)
        
        setConstrait()
    }
    func setConstrait() {
        bgImgView.snp.makeConstraints { make in
            make.centerX.lessThanOrEqualToSuperview()
            make.bottom.equalTo(kFitWidth(-18))
            make.width.equalTo(kFitWidth(347))
            make.height.equalTo(kFitWidth(95))
        }
        settleMoneyLabel.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(31))
            make.top.equalTo(kFitWidth(59))
        }
        settleMoneyLab.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(31))
            make.top.equalTo(settleMoneyLabel.snp.bottom).offset(kFitWidth(2))
        }
        handFeeLabel.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(31))
            make.top.equalTo(kFitWidth(130))
            make.height.equalTo(kFitWidth(28))
        }
        handFeeLab.snp.makeConstraints { make in
            make.left.equalTo(handFeeLabel)
            make.top.equalTo(handFeeLabel.snp.bottom).offset(kFitWidth(2))
        }
    }
}
